/**
 * @Author: 陈瑞鹏
 * @Date:   2023-01-10 09:52:04
 * @Last Modified by:   陈瑞鹏
 * @Last Modified time: 2023-01-10 18:48:08
 */
import emailCtr from "../ctrs/email/emailCtr";
import netCtr from "../ctrs/netCtr";
import BaseGameLayer from "../libs/core/BaseGameLayer";
import { PureMVCEvents } from "../libs/core/PureMVCEvents";
import { drawScroll2 } from "../libs/core/utils";
import { INotification } from "../libs/pureMvc/Interfaces";

const { ccclass, property } = cc._decorator;
@ccclass
export default class emailLayer extends BaseGameLayer {

  @property({ type: cc.Node, tooltip: "邮件列表节点" })
  listNode: cc.Node = null;

  @property({ type: cc.Prefab, tooltip: "邮件预制体" })
  emailPre: cc.Prefab = null;

  onEnable(): void {
    super.onEnable();
    this.drawUi();
  }

  protected onDataChanged(): void {
    super.onDataChanged();
  }

  public listNotificationInterests(): string[] {
    return [PureMVCEvents.ON_EMAIL_UPDATE];
  }
  public handleNotification(notification: INotification): void {
    let name = notification.getName();
    switch (name) {
      case PureMVCEvents.ON_EMAIL_UPDATE:
        this.drawUi();
        break;
    }
  }

  drawUi() {
    let arr = emailCtr.ins.emailDic.getValueList();
    drawScroll2(this.listNode, arr, this.emailPre, "emailCom", 1, 0, 10);
  }

  onYjLq() {
    netCtr.ins.yjLq();
  }

  onYjDel() {
    netCtr.ins.yjDel();
  }
}